##################################################################
# File : /lua/common/targetingmethods.lua
# Description : A targeting method is simply a system for masking allowable selections.
# Author : GPG
##################################################################

--[[
A targeting method is simply a system for masking allowable selections.

  Selection classes:      Default Priority:

   ESC_POTION                  12
   ESC_ENEMYDEMIGOD            11
   ESC_ENEMYSTRUCTURE          10
   ESC_ENEMYMINION             9
   ESC_ENEMYREINF              8
   ESC_SELF                    7
   ESC_ALLIEDDEMIGOD           6
   ESC_ALLIEDSTRUCTURE         5
   ESC_OWNMINION               4
   ESC_ALLIEDMINION            3
   ESC_ALLIEDREINF             2
   ESC_NEUTRAL                 1  
   ESC_ANY                     0
--]]

--[[
TargetMethodToBitmask
Converts a string name into a bitmask field usable by the selection system

When the targeting method of an ability is 'name' then the selectable targets are the table entries marked 'true'  Entries can be added to this
table as needed, although selection classes cannot be added without code changes.

The details of what each of these masks is intended to do is outlined in:
//depot/forge/main/design/UI/UI_Selection.doc
--]]
local bitmasks =
{
#                                        Potion  EnemyDG  EnemyStruct  EnemyMinion  EnemyReinf  Self    AlliedDG,  AlliedStruct  OwnMiniun   AlliedMinion  AlliedReinf  Neutral
    { name = 'HOSTILETARGETED', bits = { false,  true,    true,        true,        true,       false,  false,     false,        false,      false,        false,       false, }, },
    { name = 'HOSTILEMOBILE',   bits = { false,  true,    false,       true,        true,       false,  false,     false,        false,      false,        false,       false, }, },
    { name = 'AREAARGETED',     bits = { false,  false,   false,       false,       false,      false,  false,     false,        false,      false,        false,       false, }, },
    { name = 'HOSTILESTRUCTURE',bits = { false,  false,   true,        false,       false,      false,  false,     false,        false,      false,        false,       false, }, },
    { name = 'STRUCTURE',       bits = { false,  false,   true,        false,       false,      false,  false,     true,         false,      false,        false,       false, }, },
    { name = 'ALLYSTRUCTURE',   bits = { false,  false,   false,       false,       false,      false,  false,     true,         false,      false,        false,       false, }, },
    { name = 'ALLYTARGETED',    bits = { false,  false,   false,       false,       false,      true,   true,      true,         true,       true,         true,        false, }, },
    { name = 'ALLYMOBILE',      bits = { false,  false,   false,       false,       false,      true,   true,      false,        true,       true,         true,        false, }, },
    { name = 'OWNMINION',       bits = { false,  false,   false,       false,       false,      false,  false,     false,        true,       false,        false,       false, }, },
}                                                                                                                                                               

TargetMethodToBitmask = function(self,TargetMethod)
    local result = 0
    for j, type in bitmasks do
        if TargetMethod == type.name then
            bitvalue = 1
            for i, bit in type.bits do
                if bit then
                    result = result + bitvalue
                end
                bitvalue = bitvalue * 2
            end
        end
    end
    return result
end


#
#  InitializeSelectionPriorities
#
#   Called from intialization of UIWorldView.  This is a callback for tweaking the priorities of selection classes.  They're set in
#   UIWorldView anyway, but this allows us to modify stuff quickly
#
InitializeSelectionPriorities = function(view)
    view:SetSelectionPriority( 'ESC_POTION', 200 )
end
